﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;

namespace BLL
{
  public class ProductInSizeBLL
  {
    public List<ProductInSize> GetBySizeId(int sizeId)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        return data.ProductInSizes.Where(p => p.IdSize == sizeId).ToList();
      }
    }
    public List<ProductInSize> GetByProductId(string productId)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        return data.ProductInSizes.Where(p => p.IdProduct == productId).ToList();
      }
    }
    public void Add(ProductInSize obj)
     {
       using (var data =new DigitalColorCMSDataContext(_Global.StringConnect))
       {
         data.ProductInSizes.InsertOnSubmit(obj);
         data.SubmitChanges();
       }
    }
    public void DeleteBySizeId(int sizeId)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        List<ProductInSize> list = data.ProductInSizes.Where(p => p.IdSize == sizeId).ToList();
        data.ProductInSizes.DeleteAllOnSubmit(list);
        data.SubmitChanges();
      }
    }
    public void DeleteByProductId(string productId)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        List<ProductInSize> list = data.ProductInSizes.Where(p => p.IdProduct == productId).ToList();
        data.ProductInSizes.DeleteAllOnSubmit(list);
        data.SubmitChanges();
      }
    }
  }
}
